/**
 * <copyright>
 * </copyright>
 *

 */
package org.eclipse.gittab.gitTabDsl.impl;

import java.util.Collection;

import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.common.notify.NotificationChain;
import org.eclipse.emf.common.util.EList;
import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.InternalEObject;
import org.eclipse.emf.ecore.impl.ENotificationImpl;
import org.eclipse.emf.ecore.impl.MinimalEObjectImpl;
import org.eclipse.emf.ecore.util.EObjectContainmentEList;
import org.eclipse.emf.ecore.util.InternalEList;
import org.eclipse.gittab.gitTabDsl.GitTabDslPackage;
import org.eclipse.gittab.gitTabDsl.NoteValues;
import org.eclipse.gittab.gitTabDsl.Sound;
import org.eclipse.gittab.gitTabDsl.Stroke;
import org.eclipse.gittab.gitTabDsl.Tone;

/**
 * <!-- begin-user-doc -->
 * An implementation of the model object '<em><b>Tone</b></em>'.
 * <!-- end-user-doc -->
 * <p>
 * The following features are implemented:
 * <ul>
 *   <li>{@link org.eclipse.gittab.gitTabDsl.impl.ToneImpl#getSound <em>Sound</em>}</li>
 *   <li>{@link org.eclipse.gittab.gitTabDsl.impl.ToneImpl#getValue <em>Value</em>}</li>
 *   <li>{@link org.eclipse.gittab.gitTabDsl.impl.ToneImpl#getStrokes <em>Strokes</em>}</li>
 * </ul>
 * </p>
 *
 * @generated
 */
public class ToneImpl extends MinimalEObjectImpl.Container implements Tone
{
  /**
   * The cached value of the '{@link #getSound() <em>Sound</em>}' containment reference.
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @see #getSound()
   * @generated
   * @ordered
   */
  protected Sound sound;

  /**
   * The default value of the '{@link #getValue() <em>Value</em>}' attribute.
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @see #getValue()
   * @generated
   * @ordered
   */
  protected static final NoteValues VALUE_EDEFAULT = NoteValues.WHOLE;

  /**
   * The cached value of the '{@link #getValue() <em>Value</em>}' attribute.
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @see #getValue()
   * @generated
   * @ordered
   */
  protected NoteValues value = VALUE_EDEFAULT;

  /**
   * The cached value of the '{@link #getStrokes() <em>Strokes</em>}' containment reference list.
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @see #getStrokes()
   * @generated
   * @ordered
   */
  protected EList<Stroke> strokes;

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  protected ToneImpl()
  {
    super();
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  @Override
  protected EClass eStaticClass()
  {
    return GitTabDslPackage.Literals.TONE;
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public Sound getSound()
  {
    return sound;
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public NotificationChain basicSetSound(Sound newSound, NotificationChain msgs)
  {
    Sound oldSound = sound;
    sound = newSound;
    if (eNotificationRequired())
    {
      ENotificationImpl notification = new ENotificationImpl(this, Notification.SET, GitTabDslPackage.TONE__SOUND, oldSound, newSound);
      if (msgs == null) msgs = notification; else msgs.add(notification);
    }
    return msgs;
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public void setSound(Sound newSound)
  {
    if (newSound != sound)
    {
      NotificationChain msgs = null;
      if (sound != null)
        msgs = ((InternalEObject)sound).eInverseRemove(this, EOPPOSITE_FEATURE_BASE - GitTabDslPackage.TONE__SOUND, null, msgs);
      if (newSound != null)
        msgs = ((InternalEObject)newSound).eInverseAdd(this, EOPPOSITE_FEATURE_BASE - GitTabDslPackage.TONE__SOUND, null, msgs);
      msgs = basicSetSound(newSound, msgs);
      if (msgs != null) msgs.dispatch();
    }
    else if (eNotificationRequired())
      eNotify(new ENotificationImpl(this, Notification.SET, GitTabDslPackage.TONE__SOUND, newSound, newSound));
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public NoteValues getValue()
  {
    return value;
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public void setValue(NoteValues newValue)
  {
    NoteValues oldValue = value;
    value = newValue == null ? VALUE_EDEFAULT : newValue;
    if (eNotificationRequired())
      eNotify(new ENotificationImpl(this, Notification.SET, GitTabDslPackage.TONE__VALUE, oldValue, value));
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public EList<Stroke> getStrokes()
  {
    if (strokes == null)
    {
      strokes = new EObjectContainmentEList<Stroke>(Stroke.class, this, GitTabDslPackage.TONE__STROKES);
    }
    return strokes;
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  @Override
  public NotificationChain eInverseRemove(InternalEObject otherEnd, int featureID, NotificationChain msgs)
  {
    switch (featureID)
    {
      case GitTabDslPackage.TONE__SOUND:
        return basicSetSound(null, msgs);
      case GitTabDslPackage.TONE__STROKES:
        return ((InternalEList<?>)getStrokes()).basicRemove(otherEnd, msgs);
    }
    return super.eInverseRemove(otherEnd, featureID, msgs);
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  @Override
  public Object eGet(int featureID, boolean resolve, boolean coreType)
  {
    switch (featureID)
    {
      case GitTabDslPackage.TONE__SOUND:
        return getSound();
      case GitTabDslPackage.TONE__VALUE:
        return getValue();
      case GitTabDslPackage.TONE__STROKES:
        return getStrokes();
    }
    return super.eGet(featureID, resolve, coreType);
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  @SuppressWarnings("unchecked")
  @Override
  public void eSet(int featureID, Object newValue)
  {
    switch (featureID)
    {
      case GitTabDslPackage.TONE__SOUND:
        setSound((Sound)newValue);
        return;
      case GitTabDslPackage.TONE__VALUE:
        setValue((NoteValues)newValue);
        return;
      case GitTabDslPackage.TONE__STROKES:
        getStrokes().clear();
        getStrokes().addAll((Collection<? extends Stroke>)newValue);
        return;
    }
    super.eSet(featureID, newValue);
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  @Override
  public void eUnset(int featureID)
  {
    switch (featureID)
    {
      case GitTabDslPackage.TONE__SOUND:
        setSound((Sound)null);
        return;
      case GitTabDslPackage.TONE__VALUE:
        setValue(VALUE_EDEFAULT);
        return;
      case GitTabDslPackage.TONE__STROKES:
        getStrokes().clear();
        return;
    }
    super.eUnset(featureID);
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  @Override
  public boolean eIsSet(int featureID)
  {
    switch (featureID)
    {
      case GitTabDslPackage.TONE__SOUND:
        return sound != null;
      case GitTabDslPackage.TONE__VALUE:
        return value != VALUE_EDEFAULT;
      case GitTabDslPackage.TONE__STROKES:
        return strokes != null && !strokes.isEmpty();
    }
    return super.eIsSet(featureID);
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  @Override
  public String toString()
  {
    if (eIsProxy()) return super.toString();

    StringBuffer result = new StringBuffer(super.toString());
    result.append(" (value: ");
    result.append(value);
    result.append(')');
    return result.toString();
  }

} //ToneImpl
